package edu.msg.jthr.backend.service.beans;

import java.util.List;

import javax.ejb.EJB;
import javax.ejb.Stateless;

import edu.msg.jthr.backend.model.Position;
import edu.msg.jthr.backend.repository.PositionRepository;
import edu.msg.jthr.backend.repository.RepositoryException;
import edu.msg.jthr.backend.service.PositionService;
import edu.msg.jthr.backend.service.ServiceException;

@Stateless
public class PositionBean implements PositionService {

	// private static final Logger LOG = LoggerFactory
	// .getLogger(BaseRepository.class);

	@EJB
	private PositionRepository positionDAO;

	public PositionBean() {
	}

	@Override
	public void insert(Position obj) throws ServiceException {
		try {
			positionDAO.insert(obj);
			// LOG.info("Insertion succeded");
		} catch (RepositoryException e) {
			// LOG.error("Insertion failed - service", e);
			throw new ServiceException();
		}
	}

	@Override
	public Position update(Position obj) throws ServiceException {
		try {
			Position temp = positionDAO.update(obj);
			// LOG.info("Update succeded");
			return temp;
		} catch (RepositoryException e) {
			// LOG.error("Update failed - service", e);
			throw new ServiceException("Update failed - service", e);
		}
	}

	@Override
	public void delete(Position obj) throws ServiceException {
		try {
			positionDAO.delete(obj);
			// LOG.info("Delete succeded");
		} catch (RepositoryException e) {
			// LOG.error("Delete failed - service", e);
			throw new ServiceException("Delete failed - service", e);
		}
	}

	@Override
	public List<Position> getAll() throws ServiceException {
		try {
			List<Position> temp = positionDAO.getAll();
			// LOG.info("getAll succeded");
			return temp;
		} catch (RepositoryException e) {
			// LOG.error("getAll failed - service", e);
			throw new ServiceException("getAll failed - service", e);
		}
	}

	@Override
	public Position getById(Long id) throws ServiceException {
		try {
			Position temp = positionDAO.getById(id);
			// LOG.info("getById succeded");
			return temp;
		} catch (RepositoryException e) {
			// LOG.error("getById failed - service", e);
			throw new ServiceException("getById failed - service", e);
		}
	}

	public String saySomething() {
		return "Ez egy fa !";
	}
}
